/*
 * @Description:
 * @Version:
 * @Autor: kkz <keke.zhang@seaboxdata.com>
 * @Date: 2024-03-06 17:49:06
 * @LastEditors: kkz
 * @LastEditTime: 2024-03-11 14:27:43
 */

import { defineStore } from 'pinia'
import { ref } from 'vue'
//用户模块 token setToken removeToken
export const useUserStore = defineStore(
  'big-user',
  () => {
    const loginUserInfo = ref({})

    const setLoginUserInfo = (userInfo) => {
      loginUserInfo.value = userInfo
    }

    // 往本地传token
    const token = ref('')
    const setToken = (newToken) => {
      token.value = newToken
    }
    // 清空token
    const removeToken = () => {
      token.value = ''
    }

    // 往本地传user
    const user = ref({})
    const getUser = async () => {
      // const res = await userGetInfoService() // 请求获取数据
      user.value = { id: 1, username: 'admin' }
    }

    //清除user
    const setUser = (obj) => (user.value = obj)
    return {
      token,
      setToken,
      removeToken,
      user,
      getUser,
      setUser,
      loginUserInfo,
      setLoginUserInfo
    }
  },
  {
    persist: true
  }
)
